/*
 * @Author: your name
 * @Date: 2019-11-01 10:17:50
 * @LastEditTime: 2019-11-01 17:14:59
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \koa-example\src\controllers\public.js
 */

const cheerio = require('cheerio');
const superagent = require('superagent');
const charset = require('superagent-charset');
charset(superagent);

// 抓取百度新闻列表
async function publicNegativePara() {
    var url = 'http://www.qqzf.cn/lizhi63202/'; //百度新闻地址
    let result =  await superagent.get(url).charset('gbk').then((sres) => {
        let html = sres.text,
        $ = cheerio.load(html, {
            decodeEntities: false
        }) //用cheerio解析页面数据
        var arr =[];

        // hot
        $(".content p").each((index, element) => {
            var $text = $(element).text();
            arr.push($text);
        });

        return arr

    }).catch(err => {
        console.error("publicNegativePara: ",err)
    });
  
    return result

}


module.exports = {
  publicNegativePara
}